#ifndef TREE_H
#define TREE_H
#include "window.h"
#include <commctrl.h>
#include <list>

namespace win
{

	class TreeViewItem : public TV_ITEM
	{
		public:
			TreeViewItem();
			TreeViewItem(HWND window, HTREEITEM h);
			void Clear();
			void SetText(const char * text);
			void SetData(void * data);
			const char * GetText() const;
			void * GetData() const;
			bool IsExpanded() const;
	};
	
	
	class TreeItem
	{
		public:
			TreeItem();
			TreeItem(HWND window, HTREEITEM h);
			void DeleteChilds() ;
			TreeItem Append(const TreeViewItem &item);
			void DeleteItem(TreeItem item);
   			bool IsNull() const
   				{ return _handle == 0; }
   			void Expand();
   			void GetView(TreeViewItem &vitem);
   			void SetView(TreeViewItem &vitem);
   			void Select();
   			bool SelectChildByData(const void* data);
   			TreeItem Parent();
   			bool IsExpanded() const;
		private:
			void GetChilds(std::list<HTREEITEM> &list);
			HTREEITEM _handle;
			HWND _hwnd;
	};
	
	class Tree : public ChildWindow
	{
		private:
			HTREEITEM _root_item;
		public:
			Tree();
			~Tree();
			void Create(Window &parent, const int child_index);
			void SetRoot(const TreeViewItem &item);
			TreeItem GetRoot();
			// returns 0 if there is not item at the position
			HTREEITEM ItemAt(const Point &p);
   			void Select(HTREEITEM item);
   			TreeItem GetFocusItem();
   			TreeItem GetTreeItem(HTREEITEM h)
   			{
   				return TreeItem(_hwnd,h);
   			}
   			void DeleteAllItems();
	};
}
#endif 

